package com.xiaozhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xiaozhi.VO.RegisterVO;
import com.xiaozhi.entity.Student;
import com.xiaozhi.entity.Teacher;
import com.xiaozhi.mapper.TeacherMapper;
import com.xiaozhi.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 烟尘
 * @since 2023-03-15
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public List<Teacher> selectByAny(HashMap<String,Object> map) {
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        wrapper.allEq(map);
        return teacherMapper.selectList(wrapper);
    }

    @Override
    public boolean addTeacher(Teacher teacher) {
        int insert = teacherMapper.insert(teacher);
        return insert > 0;
    }

    @Override
    public boolean update(Teacher teacher) {
        UpdateWrapper<Teacher> wrapper = new UpdateWrapper<>();
        HashMap<String, Object> map = new HashMap<>();
        map.put("account",teacher.getAccount());
        wrapper.allEq(map);
        int update = teacherMapper.update(teacher, wrapper);
        return update>0;
    }

}
